package com.erpanderp.wam.tm.view;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.swing.SwingWorker;

import org.primefaces.component.datatable.DataTable;
import org.primefaces.context.RequestContext;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.primefaces.model.UploadedFile;

import com.erpanderp.wam.tm.model.entity.RRFManagerRecommendation;
import com.erpanderp.wam.tm.model.entity.RecruitmentProfile;
import com.erpanderp.wam.tm.model.entity.RecruitmentRequest;
import com.erpanderp.wam.tm.model.entity.RecruitmentVendor;
import com.erpanderp.wam.tm.model.entity.SkillRating;
import com.erpanderp.wam.tm.model.service.RRFDAO;
import com.erpanderp.wam.tm.model.service.RRFManagerRecommendationDAO;
import com.erpanderp.wam.tm.model.service.RecruitmentProfileDAO;
import com.erpanderp.wam.tm.model.service.SkillRatingDAO;
import com.erpanderp.wam.tm.model.service.VendorRegistrationDAO;
import com.erpanderp.wam.usm.model.service.user.EmployeeDAO;
import com.erpanderp.wam.util.CommonLookup;
import com.erpanderp.wam.util.EmailUtil;
import com.erpanderp.wam.util.ValidationUtil;
import com.erpanderp.wam.util.WAMHostManager;

@ManagedBean
@ViewScoped
public class UploadResourcesBean implements Serializable{

	private static final long serialVersionUID = 1L;	
	private Map<String,String> noticePeriodBuyOutMap = CommonLookup.getAuthenticationsMap();
	private TimeZone timeZone = TimeZone.getDefault();
	HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
	ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
		
	private String rrfCode;
	private String technology;
	
	private boolean FORM_VALID;
	private boolean disableBuyoutCost;
	private EmailUtil emailUtil;
	private String EMAIL_MESSAGE;
	private long recruitmentVendorId;	
	
	private UploadedFile file;
	private String fileName;
	private File realPath;
	//private StreamedContent fileDownload; 
	private StreamedContent file1; 
	
	private DataTable assignedNewResourcesTable;
	private Date dateAfterFourMnths;
		
	private RecruitmentProfile recruitmentProfile = new RecruitmentProfile();
	private RecruitmentProfile selectedRRFProfile;
	private RecruitmentProfile cvDBprofile = new RecruitmentProfile();
	private RecruitmentProfile viewRecruitmentProfile = new RecruitmentProfile();
	private RecruitmentRequest slectedRecruitmentRequest = new RecruitmentRequest();
	private RecruitmentRequest recruitmentRequest = new RecruitmentRequest();
	private RecruitmentVendor recruitmentVendor=new RecruitmentVendor();
	private RRFManagerRecommendation rrfManagerRecommendation=new RRFManagerRecommendation();
	
	private RecruitmentProfileDAO recruitmentProfileDAO=new RecruitmentProfileDAO();
	private VendorRegistrationDAO vendorRegistrationDAO=new VendorRegistrationDAO();
	private EmployeeDAO employeeDAO = new EmployeeDAO();
	private RRFDAO rrfDAO = new RRFDAO();
	private SkillRatingDAO skillRatingDAO = new SkillRatingDAO();
	private RRFManagerRecommendationDAO rrfManagerRecommendationDAO=new RRFManagerRecommendationDAO();
	
	
	private List<RecruitmentProfile> cvDBProfilies =new ArrayList<RecruitmentProfile>();
    private Map<String, Long> recruitmentVendorsMap = new HashMap<String, Long>();
	private List<RecruitmentVendor> recruitmentVendors = new ArrayList<RecruitmentVendor>();
	private List<RecruitmentProfile> recruitmentProfiles = new ArrayList<RecruitmentProfile>();
	private List<SkillRating> skillRatingsSingleLevel = new ArrayList<SkillRating>();
	private List<SkillRating> skillRatingsTwoLevel = new ArrayList<SkillRating>();
	
	private long fromExperience;
	private long toExperience;
	private String profileStatus;

	public UploadResourcesBean() {
	
		rrfCode = request.getParameter("rrfCode");
		technology = request.getParameter("technology");
		
		slectedRecruitmentRequest = rrfDAO.getRRFByRecruitmentRequestCode(rrfCode);
		
		Calendar currentDate = Calendar.getInstance();
		SimpleDateFormat formate= new SimpleDateFormat("dd/MM/yyyy");

		currentDate.setTime(slectedRecruitmentRequest.getRequestDate());
		
		//get after two months
		currentDate.add(Calendar.MONTH,4);
		
		System.out.println("===========1111111111=============="+slectedRecruitmentRequest.getRequestDate());
		try{
			//requestDate = (Date)formate.parse(toDay);
			dateAfterFourMnths = (Date)formate.parse(formate.format(currentDate.getTime()));
			System.out.println("===========dateAfterFourMnths=============="+dateAfterFourMnths);
		} catch (ParseException e) {
			e.printStackTrace();
		} 
	
		fromExperience=slectedRecruitmentRequest.getRelaventExperienceFrom();
		toExperience=slectedRecruitmentRequest.getRelaventExperienceTo();
		
		System.out.println("fromExperience========"+fromExperience);
		System.out.println("toExperience========"+toExperience);
				
		cvDBProfilies = recruitmentProfileDAO.getAllRecruitmentProfiles(technology,fromExperience,toExperience);
		
		System.out.println("cvDBProfilies===COUNT====="+cvDBProfilies.size());
		
		recruitmentVendors = vendorRegistrationDAO.getRecruitmentVendors();
		for (RecruitmentVendor recruitmentVendor : recruitmentVendors) {
			recruitmentVendorsMap.put(recruitmentVendor.getVendorName(), recruitmentVendor.getRecruitmentVendorId());
		}
		
		//recruiter=employeeDAO.getEmployeeByEmployeeId(8l);
		//enableOrDisableBuyoutCostListener(null);
		//disableBuyoutCost=true;
		
	}
	
	//VIEW FEEDBACK
	public void viewFeedbackAction(ActionEvent e){
		Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		String candidateEmail = params.get("candidateEmail");
		String rrfCode = params.get("rrfCode");
		System.out.println("candidateEmail========="+candidateEmail);
		
		recruitmentRequest = rrfDAO.getRRFByRecruitmentRequestCode(rrfCode);
		viewRecruitmentProfile=recruitmentProfileDAO.getRecruitmentProfileByCandidateEmail(candidateEmail);	
		System.out.println("===================viewRecruitmentProfile==============="+viewRecruitmentProfile.getCandidateName());
		skillRatingsSingleLevel=skillRatingDAO.getSkillRatings(rrfCode,viewRecruitmentProfile.getRecruitmentProfileId(),"Single Level");
		
		if(recruitmentRequest.getInterviewLevel().equalsIgnoreCase("Two Level")){
			skillRatingsTwoLevel=skillRatingDAO.getSkillRatings(rrfCode,viewRecruitmentProfile.getRecruitmentProfileId(),"Two Level");
		}
		rrfManagerRecommendation=rrfManagerRecommendationDAO.getRRFManagerRecomendationsByRRFCode(rrfCode,viewRecruitmentProfile.getRecruitmentProfileId());
		
	}
	
	//CLOSE dialog LISTENER
	public void dialogCloseListener(ActionEvent e){
		RequestContext.getCurrentInstance().execute("viewFeedbackDialog.hide()");
		
	}
	//GETTING EMPLOYEES BY SELECTING TECHNOLOGY
    public void changeProfileListListener(AjaxBehaviorEvent e) 
    {
    	System.out.println("INSIDE CHANGE ACTION  LISTENER ================"+profileStatus);
    	if(profileStatus.equalsIgnoreCase("All")){
    		cvDBProfilies = recruitmentProfileDAO.getAllRecruitmentProfiles(technology,fromExperience,toExperience);
    	}else if(profileStatus.equalsIgnoreCase("Open")){
    		cvDBProfilies = recruitmentProfileDAO.getAllRecruitmentProfilesByStatus(technology,fromExperience,toExperience,profileStatus);
    	}else if(profileStatus.equalsIgnoreCase("Inprocess")){
    		cvDBProfilies = recruitmentProfileDAO.getAllRecruitmentProfilesByStatus(technology,fromExperience,toExperience,profileStatus);
    	}else if(profileStatus.equalsIgnoreCase("Rejected")){
    		cvDBProfilies = recruitmentProfileDAO.getAllRecruitmentProfilesByStatus(technology,fromExperience,toExperience,profileStatus);
    	}else if(profileStatus.equalsIgnoreCase("Selected")){
    		cvDBProfilies = recruitmentProfileDAO.getAllRecruitmentProfilesByStatus(technology,fromExperience,toExperience,profileStatus);
    	}
    	
    	
    }
    
  //FILE DOWNLOAD ACTION
  		public void fileDownload(ActionEvent e) throws FileNotFoundException{
  			Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
  			String candidateEmail = params.get("candidateEmail");
  			System.out.println("filePath FROM PARAM = "+candidateEmail);
  			selectedRRFProfile = recruitmentProfileDAO.getRecruitmentProfileByCandidateEmail(candidateEmail);	
  			ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();        
  		    File result = new File(extContext.getRealPath("//RRFResumes//"+selectedRRFProfile.getUploadFilePath()));        
  		    InputStream stream = new FileInputStream(result.getAbsolutePath());
  		    setFile1(new DefaultStreamedContent(stream, "application/msword","ERPandERPDBProfile"));		
  		}

	// ACTIONS FOR CREATING NEW RESOURCE
			public String createAnotherResourceAction() {				
				validateForm();
				if (FORM_VALID) {
					try{
						RecruitmentProfile isProfileExists=null;
						 ExternalContext extContext=FacesContext.getCurrentInstance().getExternalContext();
						 fileName = file.getFileName();		
						 
						 Pattern pattern = Pattern.compile("[^a-zA-Z\\s]");
						 Matcher matcher = pattern.matcher(technology);
						 String technology1 = matcher.replaceAll("");
						 
						 File sss= new File(extContext.getRealPath("//RRFResumes//"+technology1+"//"));
						 
						 boolean isDirectoryCreated = sss.mkdir();
						 setRealPath(new File(sss+"//"+file.getFileName()));					
						 
						 
							recruitmentVendor=vendorRegistrationDAO.getRecruitmentVendorByVendorId(recruitmentVendorId);
							slectedRecruitmentRequest=rrfDAO.getRRFByRecruitmentRequestCode(rrfCode);					
							System.out.println("=============11111111================");
							recruitmentProfile.setRecruitmentRequest(slectedRecruitmentRequest);
							recruitmentProfile.setRecruitmentRequestCode(rrfCode);
							recruitmentProfile.setTechnology(technology);
							recruitmentProfile.setBand(slectedRecruitmentRequest.getBand());							
							recruitmentProfile.setRecruitmentVendor(recruitmentVendor);
							recruitmentProfile.setUploadFilePath("\\"+technology1+"\\"+fileName);//File related
							recruitmentProfile.setFileSize(file.getSize());//File related
							recruitmentProfile.setFile(file);//File related
							System.out.println("=============2222222222================");
							recruitmentProfile.setProfileCurrentStatus("Inprocess");//STATUS
							recruitmentProfile.setManagerRecommendationStatus("Not Available");
							recruitmentProfile.setInterviewer1FeedbackStatus("Not Available");
							recruitmentProfile.setInterviewer2FeedbackStatus("Not Available");
							//recruitmentProfile.setInterviewerLevel("Level1-Inprocess");
							recruitmentProfile.setCreateDate(new Date());
							recruitmentProfile.setUploadedBy(slectedRecruitmentRequest.getRecruiter());
							recruitmentProfile.setCreatedBy(CommonLookup.CREATEDBY_DEVELOPER_TEXT);
							recruitmentProfile.setStatus(CommonLookup.STATUS_ACTIVE);
							
							System.out.println("============isProfileExists=====Before======"+isProfileExists);
							
							isProfileExists=recruitmentProfileDAO.isRecruitmentProfileExists(recruitmentProfile.getCandidateEmail(),recruitmentProfile.getCandidateMobileNumber());
							System.out.println("============isProfileExists=====After======"+isProfileExists);
							if(isProfileExists != null){
								FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "This E-Mail Id/ContactNo is already exists.", ""));
							}else{
								recruitmentProfiles.add(recruitmentProfile); //ALL RECORDS LIST								
							}
							System.out.println("=============333333333333================");
							recruitmentProfile = new RecruitmentProfile();
					
					}catch (Exception e) {
						e.printStackTrace();
					}
				}
				return null;
			}	
	
	public String uploadResourcesAction() {		
	try{	
		 if (recruitmentProfiles.size() > 0 ) {
			for(RecruitmentProfile recruitmentProfile : recruitmentProfiles){
				try{					
						ExternalContext extContext=FacesContext.getCurrentInstance().getExternalContext();
						File rootPath= new File(extContext.getRealPath("//RRFResumes//"));
					    FileOutputStream fileOutputStream = new FileOutputStream(rootPath+recruitmentProfile.getUploadFilePath(),true);
						byte[] buffer = new byte[1024*1024*10];		//10MB
						int bulk;						
					    InputStream inputStream = recruitmentProfile.getFile().getInputstream();
						while (true) {
							bulk = inputStream.read(buffer);
								if (bulk < 0) {
								 break;
								}
							fileOutputStream.write(buffer, 0, bulk);
							fileOutputStream.flush();
					   }
					 fileOutputStream.close();
					 inputStream.close();	
					 
					}catch (Exception e) {
						e.printStackTrace();
					}					
				}
				//MAIL TRIGGERING CODE
				System.out.println("AT CALLER METHOD: " + sendMessage());  //*******DONT REMOVE*******
				recruitmentProfileDAO.saveRecruitmentProfiles(recruitmentProfiles);
				recruitmentProfiles = new ArrayList<RecruitmentProfile>();
				recruitmentProfile = new RecruitmentProfile();
				
				FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "Resources are uploaded successfully.", ""));
			}else{
				FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "There are no profiles to upload.", ""));
			}
		
		}catch (Exception e) {
			e.printStackTrace();
			FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Failed to upload Resources.", e.getMessage()));
		}
	
		return null;
	}
	
	// SAVE SKILL RATINGS
	public void addAlreadyProcessedProfilesAction(ActionEvent e) {
		Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		long profileId = Long.parseLong(params.get("profileId"));
		cvDBprofile = recruitmentProfileDAO.getRecruitmentProfileByProfileId(profileId);
		cvDBprofile.setRecruitmentRequest(slectedRecruitmentRequest);
		cvDBprofile.setRecruitmentRequestCode(rrfCode);
		
		
		cvDBprofile.setInterviewer1FeedbackStatus("Not Available");
		cvDBprofile.setInterviewer2FeedbackStatus("Not Available");
		cvDBprofile.setManagerRecommendationStatus("Not Available");
		recruitmentProfileDAO.saveRecruitmentProfile(cvDBprofile);
		recruitmentProfiles.add(cvDBprofile);		
	}

	//SENDING EMAIL 
		public String sendMessage(){
			Map<String, String> hostsMap = WAMHostManager.getWAMHosts(context);
			String domainName = context.getInitParameter("domainName");
			String messageString ="";		
			
			emailUtil = new EmailUtil();
			if (hostsMap.get(CommonLookup.DEV_EMAIL) == null) {
				System.out.println("PRODUCTION");
				String[] to = { slectedRecruitmentRequest.getEmployee().getEmail() };
				emailUtil.setRecieverAddresses(to);
			} else {
				System.out.println("DEVELOPMENT");
				String[] to = { hostsMap.get(CommonLookup.DEV_EMAIL) };
				emailUtil.setRecieverAddresses(to);
			}
						
			String requestURL = "tm/managershortlistprofiles.html?rrfCode=" + rrfCode;
			String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
			String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
			
			messageString = "Dear " + slectedRecruitmentRequest.getEmployee().getFirstName() + " " + slectedRecruitmentRequest.getEmployee().getLastName() + "" +
									",<br /><br />" +
									
									"<table style='border: 1px solid #d9d9d9;'>" +
							        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
							        "<tr> <td>Technology</td><td> : </td> <td>" + slectedRecruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
							        "</table><br/>"+
							        "<b>Please short list the profile(s) to proceed further interview(s)</b><br/><br/>"+
							        "<a style='color:#FF9933;font-weight: bold;' href=\""+
							        privateLink + "\">" + "Please click here to short list the profiles for interviews" + "</a /><br />"+
									"(Employees who are in Hyderabad office)"+"<br /><br />"+
									"<a style='color:#FF9933;font-weight: bold;' href=\""+
									publicLink + "\">" + "Please click here to short list the profiles for interviews" + "</a /><br />"+
									"(out side Hyderabad office)"+"<br /><br />"+
									
									"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;
			//emailUtil = new EmailUtil();
			emailUtil.setMessage(messageString);
			emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");
			
			emailUtil.setSubject("WAM - RRF Request ( "+rrfCode+" ) - View/Short List the Uploaded Profiles");
			
			SwingWorker worker = new SwingWorker<String, Object>() {
				@Override
				protected String doInBackground() throws Exception {
					EMAIL_MESSAGE = emailUtil.processAndSendEmail();
					return null;
				}

				@Override
				protected void done() {
						System.out.println("DONE " + EMAIL_MESSAGE);		
				}
			};
			worker.execute();
			System.out.println( "BEFORE RETURNING: " + EMAIL_MESSAGE);
			return EMAIL_MESSAGE;
		}
//DELETE RESORCE FROM TABLE LIST		
	public void removeRecruitmentResource(ActionEvent e){
		RecruitmentProfile selectedResource = (RecruitmentProfile) assignedNewResourcesTable.getRowData();		
		recruitmentProfiles.remove(selectedResource);
	}
	
 //Enable or disable buycost lable
	public void enableOrDisableBuyoutCostListener(AjaxBehaviorEvent e)
	{			
		String buyout = recruitmentProfile.getNoticePeriodBuyOut();
		if(buyout.equalsIgnoreCase("YES")){
			disableBuyoutCost = false;
		}
		if(buyout.equalsIgnoreCase("No")){
			disableBuyoutCost = true;
			recruitmentProfile.setNoticePeriodBuyOutCost(0l);
		}
	}		

	  
// VALIDATIONS
	private void validateForm() {
		FORM_VALID = true;
	
		
		if(file.getFileName() == null || file.getFileName().equals("") ){
	    	FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_WARN, "Upload Resume cannot be empty", ""));
	    	FORM_VALID = false;
	    }else{
	    	String fileName =file.getFileName();
			 String fileExtention = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
			 
			 if (fileExtention.equalsIgnoreCase("docx") || fileExtention.equalsIgnoreCase("doc") || fileExtention.equalsIgnoreCase("pdf") || fileExtention.equalsIgnoreCase("odt") )
	         {
				System.out.println("File should be any one of above specified format");

	         }else{
	        	 FORM_VALID = false;
				 FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Invalid file type.File name should be in .docx,.doc,.pdf or .odt", ""));
	         }		 
	    }
		if (ValidationUtil.isEmpty(recruitmentProfile.getCandidateName(), " Candidate Name", null,
				FacesContext.getCurrentInstance()) != null) {
			FORM_VALID = false;
		}
		if (ValidationUtil.isEmpty(recruitmentProfile.getCandidateEmail(), " Candidate Email", null,
				FacesContext.getCurrentInstance()) != null) {
			FORM_VALID = false;
		} else {
			System.out.println("EMAIL ENTERED");
			if (ValidationUtil.isEmailValid(recruitmentProfile.getCandidateEmail(), "Candidate Email", null,
					FacesContext.getCurrentInstance()) != null) {
				FORM_VALID = false;
			} 
		}
		if (ValidationUtil.isEmpty(recruitmentProfile.getCandidateMobileNumber(), " Candidate Contact", null,
				FacesContext.getCurrentInstance()) != null) {
			FORM_VALID = false;
		}
		
		if (ValidationUtil.isEmpty(recruitmentProfile.getCandidateCurrentLocation(), "Candidate Location",
				null, FacesContext.getCurrentInstance()) != null) {
			FORM_VALID = false;
		}	
		if (ValidationUtil.isEmpty(recruitmentProfile.getCandidateExperience(), "Total Experience",
				null, FacesContext.getCurrentInstance()) != null) {
			FORM_VALID = false;
		}else{
			int totalExp = 0;			
			try
			{
				totalExp = Integer.parseInt(recruitmentProfile.getCandidateExperience());
			}
			catch (NumberFormatException nfe)
			{
				FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_WARN, "Please enter numeric values in the experience.", ""));
				FORM_VALID = false;			
			}			
			if(totalExp > 50){
				FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_WARN, "Experience should be less than 50 years.", ""));
				FORM_VALID = false;
			}else if((totalExp < 50)){
				System.out.println("EXP IS WITH IN RANGE 50 years====");
			}else{
				FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_WARN, "Please enter numeric values in the experience.", ""));
				FORM_VALID = false;
			}
		}	
		if (ValidationUtil.isEmpty(Integer.toString(recruitmentProfile.getCandidateNoticePeriod()), "Notice Period (Days)",
				null, FacesContext.getCurrentInstance()) != null) {
			FORM_VALID = false;
		}else{
			if(recruitmentProfile.getCandidateNoticePeriod() < 0){
				FORM_VALID = false;
				FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Notice Period should be grater than zero.", ""));
				recruitmentProfile.setCandidateNoticePeriod(0);
			}	
		}
		
		if(ValidationUtil.isEmpty(recruitmentProfile.getCtc() != 0 ? String.valueOf(recruitmentProfile.getCtc()) : null , "CTC (INR)", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}else{
			if (ValidationUtil.isSalaryValid(String.valueOf(recruitmentProfile.getCtc()), "CTC (INR)", null,
					FacesContext.getCurrentInstance()) != null) {
				FORM_VALID = false;
			}
			if(recruitmentProfile.getCtc() < 0){
				FORM_VALID = false;
				FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"CTC(INR) should be grater than zero.", ""));
				recruitmentProfile.setCtc(0);
			}
		}
	   if(ValidationUtil.isEmpty(recruitmentProfile.getEctc() != 0 ? String.valueOf(recruitmentProfile.getEctc()) : null , "ECTC (INR)", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}else{
			if (ValidationUtil.isSalaryValid(String.valueOf(recruitmentProfile.getEctc()), "ECTC (INR)", null,
					FacesContext.getCurrentInstance()) != null) {
				FORM_VALID = false;
			} 
			if(recruitmentProfile.getEctc() < 0){
				FORM_VALID = false;
				FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"ECTC(INR) should be grater than zero.", ""));
				recruitmentProfile.setEctc(0);
			}
		}
		if(ValidationUtil.isEmpty((recruitmentProfile.getExpectedJoiningDate() !=null) ? recruitmentProfile.getExpectedJoiningDate().toString():null, "Expected Joining Date", null, FacesContext.getCurrentInstance()) != null){
			
			   FORM_VALID = false;
		} 
		 if(recruitmentProfile.getExpectedJoiningDate() != null){
			   if(recruitmentProfile.getExpectedJoiningDate().before(slectedRecruitmentRequest.getRequestDate())){
				   FORM_VALID = false;
				   FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Expected date of joining should be greater than rrf create date", ""));
			   }
			   if(recruitmentProfile.getExpectedJoiningDate().after(dateAfterFourMnths)){
				   FORM_VALID = false;
				   FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Expected date of joining should not be exceed 4 months (or) 120 Days", ""));
			   }
		  }
	}	
//SETTERS AND GETTERS
	public List<RecruitmentProfile> getCvDBProfilies() {
		return cvDBProfilies;
	}
	public void setCvDBProfilies(List<RecruitmentProfile> cvDBProfilies) {
		this.cvDBProfilies = cvDBProfilies;
	}
	
	public RecruitmentProfileDAO getRecruitmentProfileDAO() {
		return recruitmentProfileDAO;
	}
	public void setRecruitmentProfileDAO(RecruitmentProfileDAO recruitmentProfileDAO) {
		this.recruitmentProfileDAO = recruitmentProfileDAO;
	}

	public String getRrfCode() {
		return rrfCode;
	}
	public void setRrfCode(String rrfCode) {
		this.rrfCode = rrfCode;
	}

	public String getTechnology() {
		return technology;
	}
	public void setTechnology(String technology) {
		this.technology = technology;
	}

	public VendorRegistrationDAO getVendorRegistrationDAO() {
		return vendorRegistrationDAO;
	}
	public void setVendorRegistrationDAO(VendorRegistrationDAO vendorRegistrationDAO) {
		this.vendorRegistrationDAO = vendorRegistrationDAO;
	}

	public Map<String, Long> getRecruitmentVendorsMap() {
		return recruitmentVendorsMap;
	}
	public void setRecruitmentVendorsMap(Map<String, Long> recruitmentVendorsMap) {
		this.recruitmentVendorsMap = recruitmentVendorsMap;
	}

	public List<RecruitmentVendor> getRecruitmentVendors() {
		return recruitmentVendors;
	}
	public void setRecruitmentVendors(List<RecruitmentVendor> recruitmentVendors) {
		this.recruitmentVendors = recruitmentVendors;
	}

	public Map<String,String> getNoticePeriodBuyOutMap() {
		return noticePeriodBuyOutMap;
	}
	public void setNoticePeriodBuyOutMap(Map<String,String> noticePeriodBuyOutMap) {
		this.noticePeriodBuyOutMap = noticePeriodBuyOutMap;
	}

	public DataTable getAssignedNewResourcesTable() {
		return assignedNewResourcesTable;
	}
	public void setAssignedNewResourcesTable(DataTable assignedNewResourcesTable) {
		this.assignedNewResourcesTable = assignedNewResourcesTable;
	}

	public boolean isFORM_VALID() {
		return FORM_VALID;
	}
	public void setFORM_VALID(boolean fORM_VALID) {
		FORM_VALID = fORM_VALID;
	}

	public RecruitmentProfile getRecruitmentProfile() {
		return recruitmentProfile;
	}
	public void setRecruitmentProfile(RecruitmentProfile recruitmentProfile) {
		this.recruitmentProfile = recruitmentProfile;
	}

	public List<RecruitmentProfile> getRecruitmentProfiles() {
		return recruitmentProfiles;
	}
	public void setRecruitmentProfiles(List<RecruitmentProfile> recruitmentProfiles) {
		this.recruitmentProfiles = recruitmentProfiles;
	}

	public EmployeeDAO getEmployeeDAO() {
		return employeeDAO;
	}
	public void setEmployeeDAO(EmployeeDAO employeeDAO) {
		this.employeeDAO = employeeDAO;
	}

	public RecruitmentVendor getRecruitmentVendor() {
		return recruitmentVendor;
	}
	public void setRecruitmentVendor(RecruitmentVendor recruitmentVendor) {
		this.recruitmentVendor = recruitmentVendor;
	}

	public long getRecruitmentVendorId() {
		return recruitmentVendorId;
	}
	public void setRecruitmentVendorId(long recruitmentVendorId) {
		this.recruitmentVendorId = recruitmentVendorId;
	}

	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	public RRFDAO getRrfDAO() {
		return rrfDAO;
	}
	public void setRrfDAO(RRFDAO rrfDAO) {
		this.rrfDAO = rrfDAO;
	}

	public UploadedFile getFile() {
		return file;
	}

	public void setFile(UploadedFile file) {
		this.file = file;
	}

	public EmailUtil getEmailUtil() {
		return emailUtil;
	}

	public void setEmailUtil(EmailUtil emailUtil) {
		this.emailUtil = emailUtil;
	}

	public String getEMAIL_MESSAGE() {
		return EMAIL_MESSAGE;
	}

	public void setEMAIL_MESSAGE(String eMAIL_MESSAGE) {
		EMAIL_MESSAGE = eMAIL_MESSAGE;
	}

	public long getFromExperience() {
		return fromExperience;
	}

	public void setFromExperience(long fromExperience) {
		this.fromExperience = fromExperience;
	}

	public long getToExperience() {
		return toExperience;
	}

	public void setToExperience(long toExperience) {
		this.toExperience = toExperience;
	}

	public String getProfileStatus() {
		return profileStatus;
	}

	public void setProfileStatus(String profileStatus) {
		this.profileStatus = profileStatus;
	}

	public File getRealPath() {
		return realPath;
	}

	public void setRealPath(File realPath) {
		this.realPath = realPath;
	}

	public RecruitmentProfile getCvDBprofile() {
		return cvDBprofile;
	}

	public void setCvDBprofile(RecruitmentProfile cvDBprofile) {
		this.cvDBprofile = cvDBprofile;
	}

	public RecruitmentProfile getViewRecruitmentProfile() {
		return viewRecruitmentProfile;
	}

	public void setViewRecruitmentProfile(RecruitmentProfile viewRecruitmentProfile) {
		this.viewRecruitmentProfile = viewRecruitmentProfile;
	}

	public List<SkillRating> getSkillRatingsSingleLevel() {
		return skillRatingsSingleLevel;
	}

	public void setSkillRatingsSingleLevel(List<SkillRating> skillRatingsSingleLevel) {
		this.skillRatingsSingleLevel = skillRatingsSingleLevel;
	}

	public List<SkillRating> getSkillRatingsTwoLevel() {
		return skillRatingsTwoLevel;
	}

	public void setSkillRatingsTwoLevel(List<SkillRating> skillRatingsTwoLevel) {
		this.skillRatingsTwoLevel = skillRatingsTwoLevel;
	}
	
	public RecruitmentRequest getRecruitmentRequest() {
		return recruitmentRequest;
	}
	public void setRecruitmentRequest(RecruitmentRequest recruitmentRequest) {
		this.recruitmentRequest = recruitmentRequest;
	}

	public RRFManagerRecommendation getRrfManagerRecommendation() {
		return rrfManagerRecommendation;
	}

	public void setRrfManagerRecommendation(RRFManagerRecommendation rrfManagerRecommendation) {
		this.rrfManagerRecommendation = rrfManagerRecommendation;
	}

	public boolean isDisableBuyoutCost() {
		return disableBuyoutCost;
	}

	public void setDisableBuyoutCost(boolean disableBuyoutCost) {
		this.disableBuyoutCost = disableBuyoutCost;
	}

	public Date getDateAfterFourMnths() {
		return dateAfterFourMnths;
	}

	public void setDateAfterFourMnths(Date dateAfterFourMnths) {
		this.dateAfterFourMnths = dateAfterFourMnths;
	}

	public RecruitmentProfile getSelectedRRFProfile() {
		return selectedRRFProfile;
	}

	public void setSelectedRRFProfile(RecruitmentProfile selectedRRFProfile) {
		this.selectedRRFProfile = selectedRRFProfile;
	}

	public StreamedContent getFile1() {
		return file1;
	}

	public void setFile1(StreamedContent file1) {
		this.file1 = file1;
	}

	public TimeZone getTimeZone() {
		return timeZone;
	}

	public void setTimeZone(TimeZone timeZone) {
		this.timeZone = timeZone;
	}


}
